<?php
$pdo;
class Page{
	public function __construct(){
		require_once 'Config.php';
        $config=new Config();
		global $pdo;
        $pdo=new PDO('mysql:dbname='.$config->mysqlc['database'].';host='.$config->mysqlc['address'].';charset=utf8', $config->mysqlc['user'],$config->mysqlc['pwd']);  
        $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);  
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);   
	}
	
	public function doAdvertise($name){
		global $pdo;
		$update=$pdo->prepare('INSERT INTO `links` VALUES(NULL,:name,:ip);');
		$update->execute(array('name'=>$name,'ip'=>$_SERVER['REMOTE_ADDR']));
		
	}
	public function isVaild(){
	if(!isset($_COOKIE['ip']) && !isset($_COOKIE['count'])) {
		setcookie('ip',$_SERVER['REMOTE_ADDR'],time()+120);
		setcookie('count',1,time()+120);
		return true;
	} else if ($_COOKIE['count'] == 1){
		setcookie('count',2,time()+120);
		return true;
	} else if(($_COOKIE['ip'] == $_SERVER['REMOTE_ADDR'])&& $_COOKIE['count'] > 2){
		return false;
	}
	return false;
}
}
?>